import 'package:fish_redux/fish_redux.dart';
import '../model/normal_config_model.dart';
import 'action.dart';
import 'state.dart';

Reducer<EngineerGasOpenViewState> buildReducer() {
  return asReducer(
    <Object, Reducer<EngineerGasOpenViewState>>{
      EngineerGasOpenViewAction.action: _onAction,
      EngineerGasOpenViewAction.onSetStep: _onSetStep,
      EngineerGasOpenViewAction.onSetConfigData: _onSetConfigData,
    },
  );
}

EngineerGasOpenViewState _onAction(
    EngineerGasOpenViewState state, Action action) {
  final EngineerGasOpenViewState newState = state.clone();
  return newState;
}

EngineerGasOpenViewState _onSetStep(
    EngineerGasOpenViewState state, Action action) {
  final EngineerGasOpenViewState newState = state.clone()
    ..step = action.payload
  ..model.status = action.payload;
  return newState;
}

EngineerGasOpenViewState _onSetConfigData(
    EngineerGasOpenViewState state, Action action) {
  final EngineerGasOpenViewState newState = state.clone();
  NormalConfigModel model = action.payload['model'];
  String value = action.payload['data'];
  model.valueDesc = value;

  return newState;
}
